<?php

namespace app\admin\controller\business;

use app\admin\library\Auth;
use app\common\controller\Backend;
use think\Request;

class Privatesea extends Backend
{
    //当前对象的模型
    protected $model;

    //开启关联查询
    protected $relationSearch = true;

    // 设置数据控制的关联字段
    protected $dataLimitField = 'adminid';

    // 设置看到数据的权限
    protected $dataLimit = 'personal';

    public function __construct()
    {
        parent::__construct();

        $this->model = model('business.Business'); //model指向数据库路径
    }

    public function index()
    {
        if ($this->request->isAjax()) {
            //设置过滤方法
            $this->request->filter(['strip_tags', 'trim']);

            //如果发送的来源是 Selectpage，则转发到 Selectpage
            if ($this->request->request('keyField')) {
                return $this->selectpage();
            }

            //通过fastadmin封装函数处理前端发过来的参数
            [$where, $sort, $order, $offset, $limit] = $this->buildparams();

            $list = $this->model
                ->with(['admin'])
                ->where($where)          //搜索条件
                ->order($sort, $order)         //$sort排序字段,$order降序还是升序
                ->paginate($limit);    //调用分页函数

            $result = ['total' => $list->total(), 'rows' => $list->items()];      //返回排序总数total()和排序数据items()
            return json($result);    //返回数据
        }

        return $this->fetch();
    }
}
